﻿using System;
using System.Collections;
using System.Collections.Generic;
using Const;
using Entitas;
using UnityEngine;

public class ExchangeBackSystem : ReactiveSystem<GameEntity>
{
    public ExchangeBackSystem(Contexts context) : base(context.game)
    {
    }

    protected override ICollector<GameEntity> GetTrigger(IContext<GameEntity> context)
    {
        return context.CreateCollector(GameMatcher.ComponentsEliminate);
    }

    protected override bool Filter(GameEntity entity)
    {
        return entity.hasComponentsEliminate
               &&entity.hasComponentsExchange
               && !entity.componentsEliminate.isEliminate
               && entity.componentsExchange.exchangeState == ExchangeState.EXCHANGE;
    }

    protected override void Execute(List<GameEntity> entities)
    {
        foreach (GameEntity entity in entities)
        {
           entity.ReplaceComponentsExchange(ExchangeState.EXCHANGE_BACK);
        }
    }
}
